/*-------------------<-- Start of Description-->---------------------\ | Generate a readme.doc file under the directory you specified; | | Note: the files must include the header using the format exactly | | like this file; | |---------------------<-- End of Description-->----------------------| |--------------------------------------------------------------------| |-----------<-- Start of Files or Arguements Needed-->---------------| | Parameters: | | directory - the complete path to the directory you want to | | create your readme.doc file for; | | stopsign - the end of the file header; | | outdata - output dataset; | | fextension - the type of files you want to create readme for; | |-----------------<-- End of Arguements Needed-->--------------------| |--------------------------------------------------------------------| |------------------<-- Start of Files Created-->---------------------| | Example: %GenReadMe(directory=T:\TACHY\BIOSTAT\Duo\Projects\ | | ACED-RID\DBget\ProgComp,outdata=dircnts); | | Usage: %GenReadMe(directory=,stopsign='-----/', outdata=, | | fextension='.sas'); | \-------------------<-- End of Files Created-->---------------------*/ %macro GenReadMe(directory=,stopsign='-----*/', outdata=, fextension='.sas', type='xls'); /*---------------------------------------------\ | Copy Right: Duo Zhou; | | Created: 10-30-2001 10:46pm; | | Purpose: Generate Readme Files under the | | directory; | \---------------------------------------------*/ /* The file assumes you have your file description listed in the file header */ /* the stopsign is the end of the file header. */ %local _tmplast_ directory stopsign outdata fextension type; %let _tmplast_=&syslast; %let directory=%sysfunc(dequote(&directory)); %let fextension="%trim(%left(%upcase(%sysfunc(dequote(&fextension)))))"; %let stopsign="%sysfunc(dequote(&stopsign))"; %let olddir=&directory; %let output=&outdata; %if (%length(%trim(%left(&directory))) >1) %then %do; %if (%quote(%substr(&directory, %length(&directory), 1)) ne %quote(\)) %then %do; %let directory=&directory.\; %end; %let ddir=%substr(&directory, 1, %eval(%length(&directory)-1)); %end; %let dirrc=%sysfunc(filename(dirrf,&directory)); %let psid=%sysfunc(DOPEN(&dirrf)); %if &psid %then %do; %let today=%sysfunc(date(),mmddyy6.); %let dirrc=%sysfunc(DCLOSE(&psid)); %let dirrc=%sysfunc(filename(dirrf)); %dir(directory=&directory, outdata=_dirtmp); proc sort data=_dirtmp; by memname; run; /* Read In the files until the stopsign */ DATA _tmp1; length fileloc myinfile $ 300 line $ 2000; set _dirtmp; by memname; line=''; if index(upcase(memname), &fextension) then do; fileloc="&directory"||trim(left(memname)); infile dummy length=linelen /*filename=myinfile line=lnum*/ end=done filevar=fileloc; do until(index(line, &stopsign) or done); input @1 line $ varying2000. linelen; if (index(trim(left(line)), '|') =1) then line=substr(trim(left(line)), 2); if (index(reverse(trim(left(line))), '|') =1) then line=substr(trim(left(line)), 1, (length(trim(left(line)))-index(reverse(trim(left(line))), '|'))); output; end; end; run; /* Keep one observation per row, and concatenate the file headers */ /* into the file description.*/ data _tmp2; set _tmp1; by memname; keep memname fDesBegRow fDesEndRow fHeaderBegRow fHeaderEndRow fParaBegRow fParaEndRow fLibBegRow fLibEndrow fNeedBegRow fNeedEndrow fCreateBegRow fCreateEndrow fCommStartRow fCommEndRow; retain fDesBegRow fDesEndRow fNeedBegRow fNeedEndrow fCreateBegRow fCreateEndRow fHeaderBegRow fHeaderEndRow fParaBegRow fParaEndRow fCommStartRow fCommEndRow fLibBegRow fLibEndrow; if first.memname then do; fDesBegRow=0; fDesEndRow=0; fNeedBegRow=0; fNeedEndrow=0; fCreateBegRow=0; fCreateEndRow=0; fHeaderBegRow=0; fHeaderEndRow=0; fParaBegRow=0; fParaEndRow=0; fCommStartRow=0; fCommEndRow=0; fLibBegRow=0; fLibEndrow=0; end; if index(line, '<') and index(line, '>') and index(line, '--') and index(upcase(compbl(line)), 'START OF') and index(upcase(compbl(line)), 'HEADER') then fHeaderBegRow =_n_+1; if index(line, '<') and index(line, '>') and index(line, '--') and index(upcase(compbl(line)), 'END OF') and index(upcase(compbl(line)), 'HEADER') then fHeaderEndRow =_n_-1; if index(line, '<') and index(line, '>') and index(line, '--') and index(upcase(compbl(line)), 'END OF') and (index(upcase(compbl(line)), 'DESCRIPTION') OR index(upcase(compbl(line)), 'PURPOSE')) then fDesEndRow=_n_-1; if index(line, '<') and index(line, '>') and index(line, '--') and index(upcase(compbl(line)), 'START OF') and (index(upcase(compbl(line)), 'DESCRIPTION') OR index(upcase(compbl(line)), 'PURPOSE')) then fDesBegRow=_n_+1; if index(line, '<') and index(line, '>') and index(line, '--') and index(upcase(compbl(line)), 'START OF') and index(upcase(line), 'PARAMETER') then fParaBegRow =_n_+1; if index(line, '<') and index(line, '>') and index(line, '--') and index(upcase(compbl(line)), 'END OF') and index(upcase(line), 'PARAMETER') then fParaEndRow =_n_-1; if index(line, '<') and index(line, '>') and index(line, '--') and index(upcase(compbl(line)), 'START OF') and index(upcase(line), 'LIBRARY') then fLibBegRow=_n_+1; if index(line, '<') and index(line, '>') and index(line, '--') and index(upcase(compbl(line)), 'END OF') and index(upcase(line), 'LIBRARY') then fLibEndrow=_n_-1; if index(line, '<') and index(line, '>') and index(line, '--') and index(upcase(compbl(line)), 'START OF') and index(upcase(compbl(line)), 'NEEDED') then fNeedBegRow=_n_+1; if index(line, '<') and index(line, '>') and index(line, '--') and index(upcase(compbl(line)), 'END OF') and index(upcase(compbl(line)), 'NEEDED') then fNeedEndRow=_n_-1; if index(line, '<') and index(line, '>') and index(line, '--') and index(upcase(compbl(line)), 'START OF') and index(upcase(compbl(line)), 'CREATED') then fCreateBegRow=_n_+1; if index(line, '<') and index(line, '>') and index(line, '--') and index(upcase(compbl(line)), 'END OF') and index(upcase(compbl(line)), 'CREATED') then fCreateEndRow=_n_-1; if index(line, '<') and index(line, '>') and index(line, '--') and index(upcase(compbl(line)), 'START OF') and (index(upcase(compbl(line)), 'COMMENT') OR index(upcase(compbl(line)), 'NOTE') OR index(upcase(compbl(line)), 'EXAMPLE')) then fcommStartRow =_n_+1; if index(line, '<') and index(line, '>') and index(line, '--') and index(upcase(compbl(line)), 'END OF') and (index(upcase(compbl(line)), 'COMMENT') OR index(upcase(compbl(line)), 'NOTE') OR index(upcase(compbl(line)), 'EXAMPLE')) then fCommEndRow =_n_-1; if last.memname; run; data _tmp3; length line $4000.; merge _tmp1 _tmp2; by memname; length fname $ 50 fHead fDes fPara fLib fNeed fCreate fComm $2000 dlm $100; retain fHead fDes fPara fLib fNeed fCreate fComm; fname=memname; %if (%quote(&type) eq) or (%index(%quote(%upcase(&type)),%STR(XLS))) or (%index(%quote(%upcase(&type)),%STR(EXCEL))) or (%index(%quote(%upcase(&type)),%STR(HTML))) %then %do; dlm="
"; if first.memname then do; fhead=''; fDes='
'; fPara='
'; fLib='
'; fNeed='
'; fCreate='
'; fComm='
'; end; %end; %else %if (%index(%quote(%upcase(&type)),%STR(RTF))) or (%index(%quote(%upcase(&type)),%STR(DOC))) or (%index(%quote(%upcase(&type)),%STR(WORD))) %then %do; line=tranwrd(line, '\', '\\'); dlm='\par\-'; if first.memname then do; fHead=''; fDes=''; fPara=''; fLib=''; fNeed=''; fCreate=''; fComm=''; end; %end; if (not index(line, '-----')) and (not index(line, '=====')) and (not index(line, '____')) and (not index(line, 'ŻŻŻŻ')) and (not index(line, '<--')) and (not index(line, '>--')) then do; line=tranwrd(line,'/*', ' '); line=tranwrd(line, '*/', ' '); line=tranwrd(line, '%*', ' '); if index(upcase(line), 'PROGRAM:') or index(upcase(line), 'STUDY:') or index(upcase(line), 'VERSION:') or index(upcase(line), 'AUTHOR:') or index(upcase(line), 'DATE:') or index(upcase(line), 'TITLE:') or index(upcase(line), 'MODIFICATION:') or index(upcase(line), 'PATH:') or index(upcase(line), 'FILE SIZE:') then do; if index(line, ';') then line=tranwrd(line, ';', "; "||trim(left(dlm))); else if not index(line, ';') then line=trimn(left(compbl(line)))||"; "||trim(left(dlm)); end; end; if fHeaderBegRow<=_n_ and _n_<= fHeaderEndRow then do; fHead=compbl(trim(left(fHead)))||trimn(left(line)); fHead=tranwrd(fHead, trim(left(dlm)), trim(left(dlm))); end; if fDesBegRow<=_n_ and _n_<=fDesEndRow then do; fDes=compbl(trim(left(fDes)))||trimn(left(line)); fDes=tranwrd(fDes, trim(left(dlm)), trim(left(dlm))); end; if fParaBegRow<=_n_ and _n_<= fParaEndRow then do; fPara=compbl(trim(left(fPara)))||trimn(left(line)); fPara=tranwrd(fPara, trim(left(dlm)), trim(left(dlm))); end; if fLibBegRow<=_n_ and _n_<=fLibEndRow then do; fLib=compbl(trim(left(fLib)))||trimn(left(line)); fLib=tranwrd(fLib, trim(left(dlm)), trim(left(dlm))); end; if fNeedBegRow<=_n_ and _n_<=fNeedEndRow then do; fNeed=compbl(trim(left(fNeed)))||trimn(left(line)); fNeed=tranwrd(fNeed, trim(left(dlm)), trim(left(dlm))); end; if fCreateBegRow<=_n_ and _n_<=fCreateEndRow then do; fCreate=compbl(trim(left(fCreate)))||trimn(left(line)); fCreate=tranwrd(fCreate, trim(left(dlm)), trim(left(dlm))); end; if fCommStartRow<=_n_ and _n_<=fCommEndRow then do; fComm=compbl(trim(left(fComm)))||trimn(left(line)); fComm=tranwrd(fComm, trim(left(dlm)), trim(left(dlm))); end; if last.memname; fhead='File Size: '||trim(left(put(fsize, best12.)))||';'||trim(left(dlm))||trim(left(fhead)); %if (%quote(&type) eq) or (%index(%quote(%upcase(&type)),%STR(XLS))) or (%index(%quote(%upcase(&type)),%STR(EXCEL))) or (%index(%quote(%upcase(&type)),%STR(HTML))) %then %do; fhead='

'||trim(left(fhead)); fHead=compbl(trim(left(fHead)))||'

'; fDes=compbl(trim(left(fDes)))||'

'; fPara=compbl(trim(left(fPara)))||'

'; fLib=compbl(trim(left(fLib)))||'

'; fNeed=compbl(trim(left(fNeed)))||'

'; fCreate=compbl(trim(left(fCreate)))||'

'; fComm=compbl(trim(left(fComm)))||'

'; %end; keep memname fname fsize fdatime fHead fDes fLib fNeed fCreate fPara fComm; label fname="File Name" fsize="File Size" fdatime="Last Modified Time" fHead="File Header" fDes="File Description" fPara="Parameter" fLib="Library" fNeed="Files or Datasets Needed" fCreate="Files Created" fComm="Comment, Reference or Usage"; run; %if (%length(&output) gt 0) %then %do; /* Output a data set as &outdata*/ data &output; set _tmp3; run; %end; /* Generate a Readme.doc file under the directory you provided*/ %let readmetoday=%sysfunc(datetime(), datetime20.); %let readmedir=%sysfunc(tranwrd(%trim(%left(&ddir))\, %str(\), %str(\\))); options orientation=landscape; ods listing close; %if (%index(%quote(%upcase(&type)),%STR(RTF))) or (%index(%quote(%upcase(&type)),%STR(DOC))) or (%index(%quote(%upcase(&type)),%STR(WORD))) %then %do; %rtfinit(filename=&ddir.\_readme.rtf, data= _tmp3, title=, headskip=N, labbold=Y, labital=N, STYLE=BOX double, line=fname, TABLINES=10000, author=Duo Zhou, company=MDT, contmsg=%bquote((continued)),contjst=S) ; %rtftitle(text=%bquote(SAS Programs Under the Directory &readmedir), fontnum=3,fontsize=12,bold=Y) ; %rtfcol(var=fname, just=l, WIDTH=5, label=%bquote(File Name)) ; %rtfcol(var=fhead,WIDTH=10,just=l, label=%bquote(File Header)); %rtfcol(var=fdes,WIDTH=12,just=l, label=%bquote(Description)); %rtfcol(var=fpara,WIDTH=12,just=l, label=%bquote(Macro Parameters)); %rtfcol(var=flib,WIDTH=12,just=L, label=%bquote(Libraries)); %rtfcol(var=fneed,WIDTH=12,just=L, label=%bquote(Files Needed)); %rtfcol(var=fcreate,WIDTH=12,just=L, label=%bquote(File Created)); %rtfspend ; %rtf ; %end; %else %if (%quote(&type) eq) or (%index(%quote(%upcase(&type)),%STR(XLS))) or (%index(%quote(%upcase(&type)),%STR(EXCEL))) or (%index(%quote(%upcase(&type)),%STR(HTML))) %then %do; %let readmedir=&directory; %let readmetoday=%sysfunc(date(), mmddyy10.); %resizec(_tmp3); %if (%quote(&type) eq) or (%index(%quote(%upcase(&type)),%STR(XLS))) or (%index(%quote(%upcase(&type)),%STR(EXCEL))) %then %do; ods phtml file="&ddir.\_Readme.xls"; proc print data=_tmp3 label STYLE(header)=[FONT_FACE='Arial, Times New Roman' FONT_SIZE=12pt background=yellow] STYLE(obsheader)=[FONT_FACE='Arial, Times New Roman' FONT_SIZE=12pt background=yellow] STYLE(obs)=[FONT_FACE='Arial, Times New Roman' FONT_SIZE=12pt background=yellow]; title "SAS Programs Under the Directory &readmedir"; var fname fhead fdes fpara flib fneed fcreate fcomm / STYLE(DATA)=[BACKGROUND=white FONT_FACE='Arial, Times New Roman' FONT_SIZE=8pt]; run; ods phtml close; %end; %else %do; ods phtml file="&ddir.\_Readme.html"; proc print data=_tmp3 label STYLE(header)=[FONT_FACE='Arial, Times New Roman' FONT_SIZE=12pt background=yellow] STYLE(obsheader)=[FONT_FACE='Arial, Times New Roman' FONT_SIZE=12pt background=yellow] STYLE(obs)=[FONT_FACE='Arial, Times New Roman' FONT_SIZE=12pt background=yellow]; title "SAS Programs Under the Directory &readmedir"; var fname fhead fdes fpara flib fneed fcreate fcomm / STYLE(DATA)=[BACKGROUND=white FONT_FACE='Arial, Times New Roman' FONT_SIZE=8pt]; run; ods phtml close; %end; %end; options orientation=portrait; ods listing; /*proc datasets library=work nolist; delete _tmp1 _tmp2 _tmp3 _dirtmp; run;quit;*/ %end; %else %do; %put ==> Alert! I can%str(%')t find the directory; %put ==> "&directory".; %end; %let syslast=&_tmplast_; %mend GenReadMe;